﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace FuncionarioRefatorado
{
	public static class StringExtensions
	{
		public static string ValueOrNull(this string input)
		{
			if (string.IsNullOrEmpty(input.Trim()))
				return null;

			return input;
		}

		public static T TryParser<T>(this string input)
		{
			T retorno = default(T);
			try
			{
				Type typeToConvert = typeof(T);
				TypeConverter converter = TypeDescriptor.GetConverter(typeToConvert);
				retorno = (T)converter.ConvertFromString(input);
			}
			catch (Exception)
			{
			}

			return retorno;
		}
	}
}
